<template>
  <div class="empty-state">
    <div class="empty-content">
      <el-icon class="empty-icon" :size="iconSize">
        <component :is="iconComponent" />
      </el-icon>
      <div class="empty-title">{{ title }}</div>
      <div v-if="description" class="empty-description">{{ description }}</div>
      <div v-if="showAction" class="empty-action">
        <slot name="action">
          <el-button type="primary" @click="handleAction">
            {{ actionText }}
          </el-button>
        </slot>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { 
  Document, 
  FolderOpened, 
  Search, 
  Warning,
  InfoFilled
} from '@element-plus/icons-vue'

interface Props {
  type?: 'document' | 'folder' | 'search' | 'warning' | 'info'
  title?: string
  description?: string
  actionText?: string
  showAction?: boolean
  iconSize?: number
}

const props = withDefaults(defineProps<Props>(), {
  type: 'document',
  title: '暂无数据',
  description: '',
  actionText: '刷新',
  showAction: false,
  iconSize: 64
})

const emit = defineEmits<{
  action: []
}>()

// 计算属性
const iconComponent = computed(() => {
  const iconMap = {
    'document': Document,
    'folder': FolderOpened,
    'search': Search,
    'warning': Warning,
    'info': InfoFilled
  }
  return iconMap[props.type] || Document
})

// 方法
const handleAction = () => {
  emit('action')
}
</script>

<style lang="scss" scoped>
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  
  .empty-content {
    text-align: center;
    max-width: 400px;
    
    .empty-icon {
      color: var(--text-color-placeholder);
      margin-bottom: 20px;
    }
    
    .empty-title {
      font-size: 18px;
      color: var(--text-color-primary);
      margin-bottom: 12px;
      font-weight: 500;
    }
    
    .empty-description {
      font-size: 14px;
      color: var(--text-color-secondary);
      line-height: 1.6;
      margin-bottom: 24px;
    }
    
    .empty-action {
      // 动作按钮样式
    }
  }
}

// 不同类型的颜色
.empty-state {
  &.type-warning .empty-icon {
    color: var(--color-warning);
  }
  
  &.type-info .empty-icon {
    color: var(--color-info);
  }
  
  &.type-search .empty-icon {
    color: var(--color-primary);
  }
}
</style>
